{include file="public/header"/}
<script src="{__PUBLIC_PATH}/common/js/jquery.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<div class="layui-fluid" id="LAY-component-layer-list">
<div class="layui-row layui-col-space15">
<div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
<div class="layui-card">
<div class="layui-card-body">
    <div class="layui-form toolbar">
        <div class="layui-form-item">
            {gt name='$typeidNum' value='1'}
            <div class="layui-inline">
                <select name="typeid" id="searchTypeid">
                    <option value="">--所有文档--</option>
                    {$arctype_html|raw}
                </select>
            </div>
            {/gt}
            <div class="layui-inline">
                <input type="text" name="keywords" id="keywords" value="{$Request.param.keywords}" placeholder="标题搜索" class="layui-input">
            </div> 
            <input type="hidden" name="channel" id="channel" value="{$channel}">
            <div class="layui-inline">
                <button class="layui-btn icon-btn" lay-filter="formSubSearchUser" lay-submit><i class="layui-icon">&#xe615;</i>搜索</button>
                {if $Request.param.typeid}
                <button class="layui-btn icon-btn" data-type="Article_add" data-url="{:url('/Article/add', ['typeid'=>$Request.param.typeid])}"><i class="layui-icon">&#xe654;</i>新增文档</button>
                {else/}
                <button class="layui-btn icon-btn" data-type="Article_add" data-url="{:url('/Article/add')}"><i class="layui-icon">&#xe654;</i>新增文档</button>
                {/if}
            </div>
        </div>
    </div>
    <table class="layui-table" id="articleTable" lay-filter="articleTable"></table>
</div>
</div>
</div>
</div>
</div>
<script type="text/html" id="tableState">
<input type="checkbox" name="arcrank" data-id="{{d.aid}}" value="{{d.arcrank}}" lay-filter="arcrank" lay-skin="switch" lay-text="正常|锁定" {{d.arcrank == 0 ? 'checked':''}}>
</script>

<script type="text/html" id="tablebaidu">
<input type="checkbox" name="zzbaidu" data-id="{{d.aid}}" data-url="{{d.arcurl}}" value="{{d.zzbaidu}}" lay-filter="zzbaidu" lay-skin="switch" lay-text="已推送|未推送" {{d.zzbaidu == 1 ? 'checked':''}}>
</script>


<script type="text/html" id="userTbBar">
<a class="layui-btn layui-btn-primary layui-btn-xs" data-type="Article_edit"  data-id="{{d.aid}}">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" data-type="Article_del" data-url="{:url('/Article/del')}" data-id="{{d.aid}}" data-deltype="pseudo">删除</a>
<a class="layui-btn layui-btn-warm layui-btn-xs" href="{{d.arcurl}}" target="_blank">浏览</a>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form', 'table', 'util'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        // 渲染表格
        var insTb = table.render({
            elem: '#articleTable',
            url: "{:url('/Article/index',array('channel'=>$channel,'typeid'=>$typeid,'keywords'=>$keywords))}",
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'},
                {field:'aid',title:'ID',width:60},
                {field: 'title', title: '标题',templet: function (d) {
                    if (d.is_b) {
                        var html = '<font style="font-weight:bold;">'+d.title+'</font>';
                    } else{
                        var html = '<font>'+d.title+'</font>';
                    }
                    if (d.is_head) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>头条</b>]</span>";
                    } 
                    if (d.is_recom) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>推荐</b>]</span>";
                    } 
                    if (d.is_special) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>特推</b>]</span>";
                    } 
                    if (d.is_litpic) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>图片</b>]</span>";
                    } 
                    if (d.is_jump) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>跳转</b>]</span>";
                    } 
                    return html;
                }},
                {field: 'typename',title: '所属栏目',align: 'center',templet: function (d) {
                    if(d.typename){
                       var html = "<font>"+d.typename+"</font>";
                    }else{
                       var html = "<font style='color:red;'>数据出错！</font>"; 
                    }
                    return html;
                }, width: 150},
                {field: 'status', templet: '#tableState', title: '状态',align: 'center',width: 100},
                {field: 'zzbaidu', templet: '#tablebaidu', title: '百度推送',align: 'center',width: 100},
                {field: 'click', title: '浏览量',align: 'center',width: 80},
                {field: 'update_time', templet: function (d) {
                    return util.toDateString(d.update_time);
                }, title: '更新时间',align: 'center', width: 150},
                {title: '排序',align: 'center',templet: function (d) {
                    if(d.sort_order){
                       var html = "<input type='text' size='4' data-id='"+d.aid+"' value='"+d.sort_order+"' id='sort_order' class='layui-input' style='height:28px;'/>";
                    }else{
                       var html = ""+d.sort_order+""; 
                    }
                    return html;
                }, width: 80},
                {title: '操作',templet: '#userTbBar',align: 'center', width: 200},
            ]]
        });
        // 搜索
        form.on('submit(formSubSearchUser)', function (data) {
            window.location.href = '{:url("/Article/index")}?typeid='+data.field.typeid+'&channel='+data.field.channel+'&keywords='+data.field.keywords;
        });
        //开启关闭
        form.on('switch(arcrank)', function(obj){
            var dataid = $(this).attr('data-id');
            var pcfurl = '{:url("/index/changeTableVal")}';
            if (obj.elem.checked){
                $(this).val(0);
            }else{
                $(this).val(-1);
            }
            changeTableVal('archives','aid',dataid,'arcrank',this,pcfurl,'Content/index');
        });
        
         //百度推送
        form.on('switch(zzbaidu)', function(obj){
            var dataid = $(this).attr('data-id');
            var baiduurl = "{$Request.Domain}"+$(this).attr('data-url');
            var pcfurl = '{:url("/index/changeTableVal")}';
            if (obj.elem.checked){
                $(this).val(1);
                baiduTableVal(baiduurl,'{:url("/index/bdTableVal")}');
            }else{
                $(this).val(0);
            }
            changeTableVal('archives','aid',dataid,'zzbaidu',this,pcfurl,'Content/index');
        });
        
        $(document).on("click","#LAY-component-layer-list .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });        
        // 触发事件
        var active = {
            Article_add: function(){
                layer.open({
                    type: 2,
                    title: false,
                    closeBtn: false,
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: $(this).attr('data-url')
                });
            },
            Article_edit: function(){
                var obj = this;
                var id = $(obj).attr('data-id');
                layer.open({
                    type: 2,
                    title: false,
                    closeBtn: false,
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: '{:url("/Article/edit")}?id='+id
                });
            },
            Article_del: function(){
                delfun(this);
            }
        };
        // 监听排序
        $(document).on("change","#LAY-component-layer-list #sort_order",function(){
            var dataid = $(this).attr('data-id');
            var pcfurl = '{:url("/index/changeTableVal")}';
            changeTableVal('archives','aid',dataid,'sort_order',this,pcfurl);
        })
    });
</script>
</body>
</html>